﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Demonstartor
{
    partial class AllParams : Form
    {
        public InvolvedParametersList SelectedParams;

        public AllParams(InvolvedParametersList Parameters)
        {
            InitializeComponent();

            clbParams.Items.AddRange(Parameters.ToArray());

        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            SelectedParams = new InvolvedParametersList();
            SelectedParams.AddRange(clbParams.CheckedItems.OfType<InvolvedParameter>().ToArray());
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void tbxFindString_TextChanged(object sender, EventArgs e)
        {
            if (tbxFindString.TextLength == 0)
            {
                clbFindedParams.Visible = false;
                clbParams.Visible = true;
            }
            else
            {
                clbFindedParams.Visible = true;
                clbParams.Visible = false;

                clbFindedParams.Items.Clear();
                string SearchText = tbxFindString.Text.ToLower();

                for (int i = 0; i < clbParams.Items.Count; i++)
                {
                    string CurText = clbParams.Items[i].ToString();
                    if (CurText.ToLower().IndexOf(SearchText) != -1)
                        clbFindedParams.Items.Add(clbParams.Items[i]);
                }
            }
        }

        private void clbFindedParams_ItemCheck(object sender, ItemCheckEventArgs e)
        {
                int ItemInd = e.Index;
                int ResItemInd = clbParams.Items.IndexOf(clbFindedParams.Items[ItemInd]);
                clbParams.SetItemChecked(ResItemInd, e.NewValue == CheckState.Checked);
            
        }
    }
}
